package com.cheer.service.impl;

import com.cheer.dao.ApplicantDao;
import com.cheer.dao.OrganizationDao;
import com.cheer.dao.StandingBookReviewDao;
import com.cheer.entity.Applicant;
import com.cheer.entity.Organization;
import com.cheer.entity.StandingBookReview;
import com.cheer.service.StatisticsService;
import com.cheer.vo.StatisticsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author cheer
 */
@Service
public class StatisticsServiceImpl implements StatisticsService {

    @Autowired
    private OrganizationDao organizationDao;

    @Autowired
    private ApplicantDao applicantDao;

    @Autowired
    private StandingBookReviewDao standingBookReviewDao;

    @Override
    public StatisticsVO getStatistics(Long orgId) {
        Organization organization = organizationDao.selectById(orgId);
        if (organization == null) {
            return null;
        }
        List<Applicant> applicants = applicantDao.listByOrgPathOrJoinOrgPath(organization.getOrgPath());
        List<StandingBookReview> reviews = standingBookReviewDao.listByOrgId(orgId);
        return StatisticsVO.build(applicants, reviews);
    }

}
